package wang.hongyun.service.impl;

import com.alibaba.fastjson.JSON;
import com.dingtalk.common.utils.HttpHelper;
import com.dingtalk.open.client.ServiceFactory;
import com.dingtalk.open.client.api.model.corp.CorpUserBaseInfo;
import com.dingtalk.open.client.api.model.corp.CorpUserDetail;
import com.dingtalk.open.client.api.service.corp.CorpUserService;
import org.springframework.stereotype.Service;
import wang.hongyun.common.ServerResponse;
import wang.hongyun.service.IUserService;

/**
 * Created by Administrator on 2018-07-06.
 */
@Service("iUserService")
public class UserServiceImpl implements IUserService {

    /**
     * 根据免登授权码查询免登用户userId
     *
     * @param accessToken
     * @param code
     * @return
     * @throws Exception
     */
    public String getUserId(String accessToken, String code) throws Exception {
        String url = "https://oapi.dingtalk.com/user/getuserinfo?access_token="+accessToken+"&code="+code;
        String result = JSON.toJSONString(HttpHelper.httpGet(url));
        return result;
    }


    /**
     *
     * @param accessToken
     * @param userid
     * @return  用户信息
     * @throws Exception
     */
    public String getUser(String accessToken, String userid) throws Exception {
        String url = "https://oapi.dingtalk.com/user/get?access_token="+accessToken+"&userid="+userid;
        String result = JSON.toJSONString(HttpHelper.httpGet(url));
        return result;
    }


}
